#@layout()
#define css()
<link rel="stylesheet" type="text/css" href="#(ctx)/css/font-awesome.min.css" media="all">
<link rel="stylesheet" type="text/css" href="#(ctx)/css/jsmind.css" media="all">
<style type="text/css">
    .modal-body.modal-table {
        padding: 0;
    }
    .modal-body .table {
        margin-bottom: 0;
    }
    .table td.btn-cell {
        padding: .5rem .75rem;
    }
    .table .btn {
        min-width: inherit;
    }
</style>
#end

#define main()
<nav class="navbar navbar-dark bg-dark fixed-top">
    <div class="navbar-brand">
        <img src="#(ctx)/img/bootstrap-solid.svg" alt="" />
    </div>
    <div class="dropdown">
        <div id="navbarDropdown" class="btn-span dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
            <div class="dropdown-text"></div>
            <img src="#(ctx)/img/user.png" alt="" class="rounded-circle" />
        </div>
        <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
            <a class="dropdown-item" href="javascript:;" data-event="category">分类管理</a>
            <a class="dropdown-item" href="javascript:;" data-event="document">文档管理</a>
            <div class="dropdown-divider"></div>
            <a class="dropdown-item" href="javascript:;" data-event="manager">管理员管理</a>
            <div class="dropdown-divider"></div>
            <a class="dropdown-item" href="javascript:;" data-event="change">修改密码</a>
            <div class="dropdown-divider"></div>
            <a class="dropdown-item" href="javascript:;" data-event="quit">退出系统</a>
        </div>
    </div>
</nav>

<div class="container-fluid">
    <div id="container" class="row"></div>
</div>

<!-- 图表右键菜单 -->
<div id="chatMenu" style="display: none; position: absolute">
    <div class="list-group">
        <a href="javascript:;" class="list-group-item list-group-item-action" data-event="addnew">增加文档</a>
        <a href="javascript:;" class="list-group-item list-group-item-action" data-event="edit">修改</a>
        <a href="javascript:;" class="list-group-item list-group-item-action" data-event="cancel">取消</a>
    </div>
</div>

<!-- 提示框 -->
<div class="modal fade modal-tips" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog modal-dialog-centered modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">提示</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="关闭">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">您确定要退出本系统吗？</div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary">确定</button>
            </div>
        </div>
    </div>
</div>

<!-- 修改密码 -->
<div class="modal fade modal-change" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">修改密码</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="关闭">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form class="form-change">
                    <div class="form-group row">
                        <label class="col-4 col-sm-3 col-form-label">用户名</label>
                        <div class="col-8 col-sm-9">
                            <div class="form-control-plaintext"></div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-4 col-sm-3 col-form-label">旧密码</label>
                        <div class="col-8 col-sm-9">
                            <input name="oldWord" type="password" class="form-control oldWord" required placeholder="请输入旧密码" />
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-4 col-sm-3 col-form-label">新密码</label>
                        <div class="col-8 col-sm-9">
                            <input name="newWord" type="password" class="form-control" required placeholder="请输入新密码" />
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary">确定修改</button>
            </div>
        </div>
    </div>
</div>

<!-- 管理员 -->
<div class="modal fade modal-manager" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">管理员列表</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="关闭">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body modal-table">
                <table class="table table-hover">
                    <colgroup>
                        <col />
                        <col style="width: 70px" />
                    </colgroup>
                    <thead class="thead-light">
                    <tr>
                        <th scope="col">用户名</th>
                        <th scope="col" class="text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
            <div class="modal-footer" style="justify-content: space-between">
                <button type="button" class="btn btn-primary" data-event="addnew">增加管理员</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 添加管理员 -->
<div class="modal fade modal-addnew-manager" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">添加管理员</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="关闭">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form class="form-manager">
                    <div class="form-group row">
                        <label class="col-4 col-sm-3 col-form-label">用户名</label>
                        <div class="col-8 col-sm-9">
                            <input name="userName" type="text" class="form-control" required placeholder="请输入用户名" />
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-4 col-sm-3 col-form-label">登录密码</label>
                        <div class="col-8 col-sm-9">
                            <input name="password" type="password" class="form-control" required placeholder="请输入登录密码" />
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary">确定添加</button>
            </div>
        </div>
    </div>
</div>

<!-- 文档管理 -->
<div class="modal fade modal-document" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">文档列表</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="关闭">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body modal-table">
                <table class="table table-hover">
                    <colgroup>
                        <col />
                        <col style="width: 100px" />
                    </colgroup>
                    <thead class="thead-light">
                    <tr>
                        <th scope="col" class="document-name">文档名称</th>
                        <th scope="col" class="text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
            <div class="modal-footer" style="justify-content: space-between">
                <button type="button" class="btn btn-primary addnew" data-event="addnew">增加文档</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 文档资料 -->
<div class="modal fade modal-addnew-document" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">添加文档</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="关闭">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form class="form-document">
                <div class="modal-body">
                    <div class="form-group row">
                        <label class="col-4 col-sm-3 col-form-label doc-name">文档名称</label>
                        <div class="col-8 col-sm-9">
                            <input name="topic" type="text" class="form-control" placeholder="请输入文档名称" required />
                        </div>
                    </div>
                    <div class="form-group row doc-update">
                        <label class="col-4 col-sm-3 col-form-label">上传文档</label>
                        <div class="col-8 col-sm-9">
                            <input name="file" id="uploadfile" type="file" class="form-control-file" />
                        </div>
                    </div>
                    <div style="display: none">
                        <input type="hidden" name="path">
                        <input type="hidden" name="type">
                        <input type="hidden" name="id">
                    </div>
                    <div class="form-group row doc-direction">
                        <label class="col-4 col-sm-3 col-form-label doc-direction">显示位置</label>
                        <div class="col-8 col-sm-9">
                            <select name="direction" class="custom-select">
                                <option value="">选择显示位置</option>
                                <option value="left">左边</option>
                                <option value="right">右边</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group row doc-expanded">
                        <div class="col-4 col-sm-3">展开数据</div>
                        <div class="col-8 col-sm-9">
                            <div class="custom-control custom-switch">
                                <input id="expanded" name="expanded" type="checkbox" class="custom-control-input">
                                <label class="custom-control-label" for="expanded">&nbsp;</label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-4 col-sm-3 col-form-label doc-type">文档分类</label>
                        <div class="col-8 col-sm-9">
                            <select name="parentId" class="custom-select" required></select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">确定提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
#end

#define script()
<script type="text/javascript" src="#(ctx)/js/jsmind.js"></script>
<script type="text/javascript" src="#(ctx)/js/ajaxfileupload.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        const dom = document.getElementById('container');
        let selectedType = 0, selectedParentId = 0;
        let _resize_timeout_id = -1;
        const myChart = new jsMind({
            container: 'container',
            editable: false,
            theme: 'primary',
            default_event_handle: {
                enable_dblclick_handle: false
            }
        });
        const render = {
            isShowMaster: false,
            userInfo: sessionStorage.getItem("userInfo"),
            getUserInfo: function() {
                if (!!render.userInfo) {
                    render.userInfo = JSON.parse(render.userInfo);
                    $(".dropdown-text").text(render.userInfo.userName);
                }
            },
            showChart: function() {
                render.set_container_size();
                jsMind.util.dom.add_event(window, 'resize', render.reset_container_size);

                utils.ajaxPost({
                    url: "#(ctx)/map/chart",
                    done: function(data) {
                        myChart.show(data)
                    }
                });
            },
            set_container_size: function() {
                const cw = window.innerWidth;
                dom.style.width = cw + "px";
            },
            reset_container_size: function() {
                if (_resize_timeout_id != -1) {
                    clearTimeout(_resize_timeout_id);
                }
                _resize_timeout_id = setTimeout(function() {
                    _resize_timeout_id = -1;
                    render.set_container_size();
                    myChart.resize();
                }, 300);
            },
            showManagerList: function() {
                utils.ajaxPost({
                    url: "#(ctx)/user/list",
                    done: function(res) {
                        if (!!res) {
                            let fragment = document.createDocumentFragment();
                            res.map(function(item) {
                                let tr = document.createElement("tr");
                                tr.innerHTML = '<td>' + item.userName + '</td>' +
                                    '<td class="text-center btn-cell">\n' +
                                    '<button type="button" class="btn btn-secondary btn-sm" data-event="delete" data-value="' + item.userName + '"><i class="icon-remove"></i></button>' +
                                    '</td>';
                                fragment.append(tr);
                            });
                            $(".modal-manager tbody").html("");
                            $(".modal-manager tbody").append(fragment);
                        }
                        $(".modal-manager").modal("show");
                    }
                });
            },
            addNewManager: function() {
                $(".modal-addnew-manager input").val("");
                $(".modal-addnew-manager").modal("show");
                $(".modal-manager").modal("hide");
            },
            /**
             * 根据类型显示分类/文档列表
             * @param type 类型：0 分类 1 文档
             */
            showDocumentList: function(type) {
                utils.ajaxPost({
                    url: "#(ctx)/map/" + (type == 0 ? 'category' : 'list'),
                    done: function(res) {
                        if (!!res) {
                            let fragment = document.createDocumentFragment();
                            res.map(function(item) {
                                let tr = document.createElement("tr");
                                tr.innerHTML = '<td>' + item.topic + '</td>' +
                                    '<td class="text-center btn-cell" data-type="' + item.type + '" data-parent="' + item.parentId + '" data-value="' + item.id + '">\n' +
                                    '<button type="button" class="btn btn-primary btn-sm" data-event="edit"><i class="icon-edit"></i></button>\n' +
                                    '<button type="button" class="btn btn-secondary btn-sm" data-event="delete"><i class="icon-remove"></i></button>' +
                                    '</td>';
                                fragment.append(tr);
                            });
                            $(".modal-document tbody").html("");
                            $(".modal-document tbody").append(fragment);
                        }
                        $(".modal-document .addnew").text(type == 0 ? "增加分类" : "增加文档");
                        $(".modal-document .modal-title").text(type == 0 ? "分类列表" : "文档列表");
                        $(".modal-document .document-name").text(type == 0 ? "分类名称" : "文档名称");
                        $(".modal-document").modal("show");
                        render.isShowMaster = true;
                    }
                });
            },
            /**
             * 初始化文档/分类录入界面
             * @param type  类型：0 分类 1 文档
             * @param parentId 上级编号
             * @param currentId 当前分类编号
             * @param callback 回调函数
             */
            initDocument: function(type, parentId, currentId, callback) {
                utils.ajaxPost({
                    url: '#(ctx)/map/' + (type == 0 ? "parentRoot" : "category"),
                    done: function(res) {
                        let options = "";
                        res.map(function(item) {
                            if (item.id != currentId) {
                                options += '<option value="' + item.id + '">' + item.topic + '</option>';
                            }
                        });
                        
                        $(".modal-addnew-document .modal-title").text(type == 0 ? "添加分类" : "添加文档");
                        $(".modal-addnew-document .doc-name").text(type == 0 ? "分类名称" : "文档名称");
                        $('.modal-addnew-document input[name="topic"]').attr("placeholder", type == 0 ? "请输入分类名称" : "请输入文档名称");
                        $(".modal-addnew-document .doc-type").text(type == 0 ? "上级分类" : "文档分类");
                        $(".modal-addnew-document .doc-update").css("display", type == 0 ? "none" : "flex");
                        $(".modal-addnew-document .doc-direction").css("display", type == 0 ? "flex" : "none");
                        $(".modal-addnew-document .doc-expanded").css("display", type == 0 ? "flex" : "none");

                        $(".modal-addnew-document input").val("");
                        $('.modal-addnew-document input[name="type"]').val(type);
                        if (!$('.modal-addnew-document select[name="direction"]').val()) {
                            $('.modal-addnew-document select[name="direction"]').val("");
                        }
                        $('.modal-addnew-document input[name="expanded"]').val('true');
                        $('.modal-addnew-document input[name="expanded"]').prop("checked", true);
                        $('.modal-addnew-document select[name="parentId"]').html(options);
                        if (!!parentId) {
                            $('.modal-addnew-document select[name="parentId"]').val(parentId);
                        }
                        
                        return typeof callback == 'function' && callback();
                    }
                });
            },
            /**
             * 新增分类/文档
             * @param type  类型：0 分类 1 文档
             * @param parentId 上级编号
             */
            addNewDocument: function(type, parentId) {
                render.initDocument(type, parentId, -1, function() {
                    $(".modal-addnew-document").modal("show");
                    $(".modal-document").modal("hide");
                });
            },
            /**
             * 修改分类/文档资料
             * @param type  类型：0 分类 1 文档
             * @param parentId 上级编号
             * @param mindId 要修改的分类/文档编号
             */
            editDocument: function(type, parentId, mindId) {
                render.initDocument(type, parentId, mindId, function() {
                    utils.ajaxPost({
                        url: '#(ctx)/map/detail',
                        data: JSON.stringify({ mindId: mindId }),
                        done: function(res) {
                            $('.modal-addnew-document input[name="topic"]').val(res.topic);
                            $('.modal-addnew-document input[name="path"]').val(res.path);
                            $('.modal-addnew-document input[name="id"]').val(res.id);
                            $('.modal-addnew-document select[name="parentId"]').val(res.parentId);
                            $('.modal-addnew-document select[name="direction"]').val(res.direction || "");
                            $('.modal-addnew-document input[name="expanded"]').val(res.expanded || 'true');
                            $('.modal-addnew-document input[name="expanded"]').prop("checked", res.expanded || true);
                            
                            $(".modal-addnew-document").modal("show");
                            $(".modal-document").modal("hide");
                        }
                    })
                });
            }
        };
        
        render.getUserInfo();
        render.showChart();
        
        // 定义jsMind节点右键弹出菜单
        $('#container').on('contextmenu', "jmnode:not(.root)", function(event) {
            const selectedNode = myChart.get_selected_node();
            $('#chatMenu').css({
                'z-index': 99,
                'left': event.clientX,
                'top': event.clientY + 20
            });
            selectedType = selectedNode.data.type;
            selectedParentId = selectedNode.data.parentId || 0;
            $('#chatMenu').attr('data-value', selectedNode.id);
            $('#chatMenu').show();
            event.preventDefault();
            return false;
        }).on('click', 'jmnode', function() {   // 点击选择jsMind节点事件
            const selectedNode = myChart.get_selected_node();
            if (!!selectedNode && !!selectedNode.data) {
                if (selectedNode.data.type == 1 && !!selectedNode.data.path) {
                    let url = "#(uploadUrl)/";
                    if (url.toLowerCase().indexOf("http:") != 0 && url.toLowerCase().indexOf("https:") != 0) {
                        url = "#(ctx)" + url;
                    }
                    const win = window.open(url + selectedNode.data.path);
                    if (!win) {
                        location.href = url + selectedNode.data.path;
                    }
                }
            }
        });
        // 弹出菜单
        $("#chatMenu").on("click", ".list-group-item", function(event) {
            event.preventDefault();
            const eventName = $(this).attr("data-event");
            const selectedId = $('#chatMenu').attr("data-value");
            if (eventName == "addnew") {
                selectedType = 1;
                selectedParentId = selectedId;
                render.addNewDocument(selectedType, selectedParentId);
                render.isShowMaster = false;
            } else if (eventName == "edit") {
                render.editDocument(selectedType, selectedParentId, selectedId);
                render.isShowMaster = false;
            } else {
                $('#chatMenu').attr('data-value', "");
            }
            $('#chatMenu').hide();
        }).on("mouseleave", function() {
            $('#chatMenu').attr('data-value', "");
            $('#chatMenu').hide();
        });

        $(".dropdown").on("click", ".dropdown-item", function(event) {
            event.preventDefault();
            const eventName = $(this).attr("data-event");
            if (eventName == "category" || eventName == "document") {
                selectedType = (eventName == "category" ? 0 : 1);
                render.showDocumentList(selectedType);
            } else if (eventName == "manager") {
                render.showManagerList();
            } else if (eventName == "change") {
                if (!!render.userInfo) {
                    $(".modal-change .form-control-plaintext").text(render.userInfo.userName);
                    $(".modal-change").modal("show");
                }
            } else if (eventName == "quit") {
                $(".modal-tips .btn-primary").attr("data-event", "quit");
                $(".modal-tips .modal-body").text("您确定要退出本系统吗？");
                $(".modal-tips").modal("show");
            }
        });

        // 提示
        $(".modal-tips").on("click", ".btn-primary", function() {
            const eventName = $(this).attr("data-event");
            let url = "", data = {};
            
            if (eventName == "quit") {
                url = "#(ctx)/logout";
            } else if (eventName == "delUser") {
                url = "#(ctx)/user/delete";
                data = { userName: $(this).attr("data-value")};
            } else if (eventName == "delMind") {
                url = "#(ctx)/map/delete";
                data = { mindId: $(this).attr("data-value"), mindType: selectedType };
            }
            
            if (!!url) {
                utils.ajaxPost({
                    url,
                    data: JSON.stringify(data),
                    done: function(res) {
                        utils.showToast(res, "icon-success", true, function() {
                            if (eventName == "delUser") {
                                render.showManagerList();
                            } else if (eventName == "delMind") {
                                render.showDocumentList(selectedType);
                            }
                        });
                    }, complete: function() {
                        $(".modal-tips").modal("hide");
                    }
                });
            }
        });

        // 修改密码
        $(".modal-change").on("shown.bs.modal", function() {
            $(".modal-change .oldWord").focus();
        }).on("click", ".btn-primary", function() {
            const data = utils.formValue($("form.form-change"));
            utils.ajaxPost({
                url: "#(ctx)/user/reset",
                data: JSON.stringify(data),
                done: function(res) {
                    utils.showToast(res, "icon-success", true);
                }, complete: function() {
                    $(".modal-change").modal("hide");
                }
            });
            return false;
        });
        
        // 管理员管理
        $(".modal-manager").on("click", "button", function() {
            const eventName = $(this).attr("data-event");
            if (eventName == "addnew") {
                render.addNewManager();
            } else if (eventName == "delete") {
                $(".modal-tips .btn-primary").attr("data-value", $(this).attr("data-value"));
                $(".modal-tips .btn-primary").attr("data-event", "delUser");
                $(".modal-tips .modal-body").text("您确定要删除该管理员吗？");
                $(".modal-tips").modal("show");
                $(".modal-manager").modal("hide");
            }
        });

        // 新增管理员
        $(".modal-addnew-manager").on("click", ".btn-primary", function() {
            const data = utils.formValue($("form.form-manager"));
            utils.ajaxPost({
                url: "#(ctx)/user/save",
                data: JSON.stringify(data),
                done: function(res) {
                    utils.showToast(res, "icon-success", true, function() {
                        render.showManagerList();
                    });
                }, complete: function() {
                    $(".modal-addnew-manager").modal("hide");
                }
            });
            return false;
        }).on("hidden.bs.modal", function(e) {
            $(".modal-manager").modal("show");
        });
        
        // 文档管理
        $(".modal-document").on("click", "button", function() {
            const eventName = $(this).data("event");
            const $parent = $(this).parent();
            const dataValue = $parent.data("value");
            const dataParent = $parent.data("parent");
            
            if (eventName == "addnew") {
                render.addNewDocument(selectedType, selectedParentId);
            } else if (eventName == "delete") {
                $(".modal-tips .btn-primary").attr("data-value", dataValue);
                $(".modal-tips .btn-primary").attr("data-event", "delMind");
                $(".modal-tips .modal-body").text(selectedType == "category" ? "您确定要删除该分类吗？" : "您确定要删除该文档吗？");
                $(".modal-tips").modal("show");
                $(".modal-document").modal("hide");
            } else if (eventName == "edit") {
                selectedParentId = dataParent;
                render.editDocument(selectedType, dataParent, dataValue);
            }
        });
        // 编辑/修改文档
        $(".modal-addnew-document").on("click", ".btn-primary", function() {
            let data = utils.formValue($("form.form-document"));
            if (data.type == 1) {
                $.ajaxFileUpload({
                    url: "#(ctx)/map/upload?token=" + render.userInfo.token,
                    fileElementId: "uploadfile",
                    dataType: "json",
                    success: function(res) {
                        if (res.code == 0) {
                            if (!!res.data) {
                                $('.modal-addnew-document input[name="path"]').val(res.data);
                                data.path = res.data;
                            }
                            utils.ajaxPost({
                                url: "#(ctx)/map/save",
                                data: JSON.stringify(data),
                                done: function(res) {
                                    utils.showToast(res, "icon-success", true, function() {
                                        render.showDocumentList(data.type);
                                    });
                                }, complete: function() {
                                    $(".modal-addnew-document").modal("hide");
                                }
                            })
                        }
                    }, error: function(res) {
                        console.log(res)
                    }
                });
            } else {
                utils.ajaxPost({
                    url: "#(ctx)/map/save",
                    data: JSON.stringify(data),
                    done: function(res) {
                        utils.showToast(res, "icon-success", true, function() {
                            render.showDocumentList(data.type);
                        });
                    }, complete: function() {
                        $(".modal-addnew-document").modal("hide");
                    }
                })
            }
            return false;
        }).on("hidden.bs.modal", function(e) {
            if (render.isShowMaster) {
                const type = $('.modal-addnew-document input[name="type"]').val();
                render.showDocumentList(type);
            }
            render.showChart();
        }).on("change", ".form-control-file", function() {
            const topic = $("input[name='topic']").val();
            if (!topic) {
                const fileName = this.files[0].name || '';
                const lastdot = fileName.lastIndexOf('.');
                $("input[name='topic']").val(lastdot > -1 ? fileName.substring(0, lastdot) : fileName);
            }
        }).on("change", "select[name='parentId']", function() {
            selectedParentId = $(this).val();
        }).on("change", "input[name='expanded']", function() {
            $(this).val($(this).prop("checked"));
        });
    });
</script>
#end
